package service;

import common.pojo.Page;
import common.utils.DateUtils;
import common.utils.MyMapUtils;
import dao.ChatListDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import pojo.ChatList;
import pojo.form.ChatListAddForm;
import pojo.form.ChatListQueryForm;

import java.util.Date;

/**
 * Created by asus on 2018/11/22.
 */
@Service
public class ChatListService {
    @Autowired
    ChatListDao chatListDao;

    public int addCharList(ChatListAddForm addForm) {
        return chatListDao.addCharList(addForm);
    }

    public int addCharRecordExist(ChatListAddForm addForm){
        return chatListDao.addCharRecordExist(addForm);
    }

    public Page<ChatList> getChatList(ChatListQueryForm queryForm, int curPage, int pageSize) {
        Page<ChatList> listPage = chatListDao.getChatList(queryForm, curPage, pageSize);
        if(listPage.getResult().size()>0){
            for (ChatList list:listPage.getResult()){
                if(DateUtils.getDistanceOfTwoDate(list.getMessageTime(),new Date())>0){
                    list.setTime(DateUtils.formatDate(list.getMessageTime(),"yyyy-MM-dd"));
                }else {
                    if(list.getMessageTime()!=null){
                        list.setTime(DateUtils.formatDate(list.getMessageTime(),"HH:mm"));
                    }
                }
            }
        }
        return listPage;
    }
}